package com.xw.musicplayer.engine;

import com.xw.musicplayer.listener.IMediaPlayer;

/**
 * 播放器工厂,负责创建出一个播放器.
 */
public class PlayerFactory {

    private static Class<? extends IMediaPlayer> sPlayerClazz;

    public static void setPlayer(Class<? extends IMediaPlayer> playerClazz) {
        sPlayerClazz = playerClazz;
    }

    public static IMediaPlayer getPlayManager() {
        if (sPlayerClazz == null) {
//            sPlayerClazz = SystemMediaPlayer.class;
            sPlayerClazz = ExoMediaPlayer.class;
        }
        try {
            return sPlayerClazz.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }

}
